import { Column, Entity, JoinColumn, OneToMany, PrimaryGeneratedColumn } from 'typeorm';
import { RoleMenu } from '@/modules/system/role-menu/entities/role-menu.entity';
import { Api } from '@/modules/system/api/entities/api.entity';
import { BaseTimeEntity } from '@/common/entities/base-time.entity';
import { TABLE_PREFIX } from '@/config';


@Entity({name:`${TABLE_PREFIX}sys_menu`})
export class Menu extends BaseTimeEntity {
    @PrimaryGeneratedColumn()
    id: number;
    
    @Column({ type: "varchar", comment: "菜单名称" })
    menuName: string;
    
    @Column({ type: "varchar", comment: "菜单编号" })
    menuKey: string;
    
    @Column({ type: "varchar", comment: "菜单图标", nullable: true })
    menuIcon: string;
    
    @Column({ type: "varchar", comment: "路由路径", nullable: true })
    path: string;
    
    @Column({ type: "varchar", comment: "前端路由组件地址", nullable: true })
    componentPath: string;
    
    @Column({ type: "int", comment: "菜单类型 1-菜单 2按钮 3跳转外链", default: 1 })
    menuType: number;
    
    @Column({ type: "int", comment: "字典排序", default: 0 })
    sort: number;
    
    @Column({ type: "varchar", comment: "备注", nullable: true })
    remark: string;
    
    @Column({ type: "int", comment: "父亲id", default: -1 })//默认为-1 ，-1就是代表顶级
    parentId: number;
    
    @OneToMany(() => RoleMenu, (roleMenu) => roleMenu.menu)
    roleMenu: RoleMenu[];
    
    @OneToMany(() => Api, (api) => api.menu)
    @JoinColumn({ name: 'menuId' })
    api: Api[];
}
